import Vue from 'vue'
import VueRouter from 'vue-router'

import Layout from '../layout' //布局页
import notFoundRoute from '../views/error/404.vue'

Vue.use(VueRouter)

//解决重复点击左侧菜单的报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


export const asyncRoutes = [
  {
    path: '/',
    redirect: '/category/category',
    component: Layout,
    // children: [
    //   {
    //     path: '/index',
    //     component: () => import('@/views/index/index.vue'),
    //     meta: {
    //       title: "首页",
    //       icon: 'el-icon-s-home',
    //     }
    //   },
    // ]
  },
  {
    path: '/category',
    component: Layout,
    redirect: '/category/category',
    meta: {
      title: "职位类型",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: 'category',
        name: 'category',
        component: () => import('@/views/category/index.vue'),
        meta: {
          title: "职位大类",
        }
      },
      {
        path: 'postCategory',
        name: 'postCategory',
        component: () => import('@/views/postCategory/index.vue'),
        meta: {
          title: "职位小类",
        }
      },
    ]
  },
  {
    path: '/city',
    component: Layout,
    redirect: '/city/city',
    meta: {
      title: "开通城市",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: 'city',
        name: 'city',
        component: () => import('@/views/city/index.vue'),
        meta: {
          title: "开通城市",
        }
      },
    ]
  },
  {
    path: '/policy',
    component: Layout,
    redirect: '/policy/policy',
    meta: {
      title: "隐私协议",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: 'policy',
        name: 'policy',
        component: () => import('@/views/policy/index.vue'),
        meta: {
          title: "隐私协议",
        }
      },
    ]
  },
  {
    path: '/resume',
    component: Layout,
    redirect: '/resume/resume',
    meta: {
      title: "简历库",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: 'resume',
        name: 'resume',
        component: () => import('@/views/resume/index.vue'),
        meta: {
          title: "简历库",
        }
      },
    ]
  },
  {
    path: '/post',
    component: Layout,
    redirect: '/post/post',
    meta: {
      title: "职位库",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: 'post',
        name: 'post',
        component: () => import('@/views/post/index.vue'),
        meta: {
          title: "职位库",
        }
      },
      {
        path: 'postJoin',
        name: 'postJoin',
        component: () => import('@/views/post/postJoin.vue'),
        meta: {
          title: "投递记录",
        }
      },
    ]
  },
  {
    path: '/rechargeConfig',
    component: Layout,
    redirect: '/rechargeConfig/config',
    meta: {
      title: "费用管理",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: 'config',
        name: 'config',
        component: () => import('@/views/rechargeConfig/index.vue'),
        meta: {
          title: "配置管理",
        }
      },
      {
        path: 'record',
        name: 'record',
        component: () => import('@/views/rechargeRecord/index.vue'),
        meta: {
          title: "消费记录",
        }
      },
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/user',
    meta: {
      title: "用户管理",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/user/index.vue'),
        meta: {
          title: "会员用户",
        }
      },
      {
        path: 'company',
        name: 'company',
        component: () => import('@/views/company/index.vue'),
        meta: {
          title: "企业用户",
        }
      },
      {
        path: 'staff',
        name: 'staff',
        component: () => import('@/views/staff/index.vue'),
        meta: {
          title: "我的员工",
        }
      },
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/Login'),
    meta: {
      title: "欢迎登录",
    },
    hidden: true //导航菜单忽略选项
  },
  {
    path: '/404',
    meta: {
      title: "页面走丢了",
    },
    component: notFoundRoute,
    hidden: true //导航菜单忽略选项
  },
]


const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: asyncRoutes
})

export default router
